package com.lh0811.forge.dependency.security.client.component;

import com.lh0811.forge.dependency.basic_code.SpringBeanHelper;
import com.lh0811.forge.dependency.basic_web.exception.CommonException;
import com.lh0811.forge.dependency.basic_web.response.ServerResponse;
import com.lh0811.forge.dependency.security.client.service.SecurityClient;
import com.lh0811.forge.dependency.security.core.model.entity.SecurityAuthority;
import org.apache.commons.lang3.ObjectUtils;

/**
 * @author lh0811
 * @date 2022/6/28
 */
public class SecurityUtil {
    public static SecurityAuthority getSecurityAuthority() throws Exception {
        SecurityAuthority securityAuthority = SpringBeanHelper.getBean(SecurityClient.class).tokenToAuthority();
        if (ObjectUtils.isNotEmpty(securityAuthority)) {
            return securityAuthority;
        }
        throw CommonException.create(ServerResponse.createByError("未获取到用户登录信息，请登录后重试"));
    }
}
